package com.zqx.iterator.client;

import com.sun.org.apache.bcel.internal.generic.NEW;
import com.zqx.iterator.absrtactaggregation.AbstractObjectList;
import com.zqx.iterator.abstractiterator.AbstractIterator;
import com.zqx.iterator.specificaggregation.ProductList;

import java.util.AbstractList;
import java.util.ArrayList;
import java.util.List;

/**
 * description: 客户端测试类
 * @author zqx
 * @date 2018/09/04
 */
public class Client {

    public static void main(String[] args) {
        List<Object> products = new ArrayList<>();
        products.add("张玉娜1");
        products.add("张玉娜2");
        products.add("张玉娜3");
        products.add("张玉娜4");

        AbstractObjectList list = new ProductList(products);//创建聚合对象
        AbstractIterator iterator = list.createIterator();//创建迭代器对象

        System.out.println("正向遍历");
        while(!iterator.isLast())
        {
            System.out.println(iterator.getNextItem()+"，");
            iterator.next();
        }
        System.out.println();
        System.out.println("=======================================");
        System.out.println("逆向遍历");
        while (!iterator.isFirst()){
            System.out.println(iterator.getPreviousItem()+",");
            iterator.previous();
        }
    }
}
